import 'package:flutter/material.dart';
import 'package:my_flutter/views/home/home.dart';
import 'package:my_flutter/views/information/information.dart';
import 'package:my_flutter/views/me/me.dart';

void main(List<String> args) {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData(useMaterial3: true),
      home: const MyAppContent(),
    );
  }
}

class MyAppContent extends StatefulWidget {
  const MyAppContent({super.key});

  @override
  State<MyAppContent> createState() => _MyAppContentState();
}

class _MyAppContentState extends State<MyAppContent> {
  int _currentIndex = 0;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      bottomNavigationBar: BottomNavigationBar(
        currentIndex: _currentIndex,
        unselectedFontSize: 14,
        selectedItemColor: Colors.amber[900],
        type: BottomNavigationBarType.fixed,
        items: <BottomNavigationBarItem>[
          tabBarItem(Icons.home, '首页'),
          tabBarItem(Icons.date_range, '信息'),
          tabBarItem(Icons.people, '我的')
        ],
        onTap: (index) {
          setState(() {
            _currentIndex = index;
          });
        },
      ),
      body: IndexedStack(
        index: _currentIndex,
        children: const [
          Home(),
          Information(),
          Me(),
        ],
      ),
    );
  }

  BottomNavigationBarItem tabBarItem(icon, title) {
    return BottomNavigationBarItem(icon: Icon(icon), label: title);
  }
}
